#ifndef NODE_H
#define NODE_H

#include <list>
#include "entity.h"
#include "frustum.h"
#include "collider.h"
#include "TerrainClump.h"
class Node
{
public:
	Node(Node* parent, int levels, int totalLevels, float x, float y, float z, float radius);
	~Node(void);
	
	bool addChild(Node* parent, int levels, int totalLevels, float x, float y, float z, float rad);
	Node** getChildren() { return children; }
	std::list<Entity*>* getEntities() { return entities; }
	std::list<TerrainClump*>* getTerrainClumps() { return clumps; }
	void addEntity(Entity* ent) { entities->push_back(ent); }
	void addTerrainClump(TerrainClump* clump) { clumps->push_back(clump); }
	void removeEntity(Entity* ent) { entities->remove(ent); }
	void clearEntities() { entities->clear(); }
	bool entityInNode(Entity* ent); //checks if entity is in node by bounding volumes
	bool clumpInNode(TerrainClump* clump);
	void putInNode(Entity* ent); //recursively puts an entity into the lowest node possible, stops when it reaches a leaf or the entity is inside 2 nodes
	void putInNode(TerrainClump* clump);
	int getNumChildren() { return numChildren; }
	int getChildNumber(Node* node);

	void removeAllEntities();

	void render(int mode, Frustum& frustum);

	void fizzle();
private:
	Node* m_parent; // parent node
	Node* children[8];

	Vector3 location; //center of node
	float size;

	int level; //level of the tree
	int numChildren;
	std::list<Entity*>* entities; //list of entities in this node
	std::list<TerrainClump*>* clumps;
};
#endif
